import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';

///
/// @DIR_PATH：lib/page/common
/// @TIME：2024/6/22 16:41
/// @AUTHOR：starr
///
class Loading {
  Loading._(); //私有化构造方法
  static bool showing = false;

  static void dismissAll() {
    dismissAllToast();
    showing = false;
  }

  static Future show({Duration? duration}) async {
    if(!showing){
      showing = true;
      showToastWidget(
          Container(
            constraints: const BoxConstraints.expand(),//并且撑满整个屏幕
            color: Colors.transparent,
            child: Align(
                child: Container(
                  padding: const EdgeInsets.all(20),
                  decoration: BoxDecoration(borderRadius: BorderRadius.circular(20),color: Colors.grey),
                  child: const CircularProgressIndicator(//圆形进度指示器
                    //圆形进度指示器
                    strokeWidth: 2,
                    valueColor: AlwaysStoppedAnimation(Colors.white),
                  ),
                )
            ),
          ),
          duration: duration ?? const Duration(days: 1),
          handleTouch: true //无法触摸屏幕
      );
    }
  }
}
